package com.software.levelupandroid.taskIssue.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.software.levelupandroid.R;
import com.software.levelupandroid.entity.Label;

import java.util.List;
import java.util.Map;

public class LabelAdapter extends BaseAdapter {
    private List<Label> iLabels;
    Context mContext;
    int layoutId;
    TextView button;
    ImageView img;


    public LabelAdapter() {
    }

    public LabelAdapter(List<Label> iLabels, Context mContext, int layoutId, TextView button, ImageView img) {
        this.iLabels = iLabels;
        this.mContext = mContext;
        this.layoutId = layoutId;
        this.button = button;
        this.img = img;
    }

    @Override
    public int getCount() {
        return iLabels.size();
    }

    @Override
    public Object getItem(int position) {
        return iLabels.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView =  LayoutInflater.from(mContext).inflate(R.layout.label_item, null);
        TextView textView = (TextView) convertView.findViewById(R.id.label_text);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.label_image);
        LinearLayout linearLayout = (LinearLayout) convertView.findViewById(R.id.label_item);

        Label item = iLabels.get(position);
        String name =  item.getTagTitle();
        Integer pic_id = Integer.parseInt(item.getIcon());
        textView.setText(name);
        imageView.setImageResource(pic_id);

        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button.setText(name);
                img.setImageResource(pic_id);
            }
        });


        return convertView;
    }


}
